﻿using Microsoft.VisualStudio.TestTools.UITest.Extension;
using System;

namespace AXExtension
{
	/// <summary>
	/// Allows you to make a UITechnologyElement when you
	/// have the IUITechnologyElement along with its top
	/// level element and its manager.
	/// </summary>
	class UITechnologyElementRedirect : UITechnologyElement
	{
		private IUITechnologyElement element;
		private UITechnologyElement topLevel;
		private UITechnologyManager manager;
		private string managerName;

		public UITechnologyElementRedirect(IUITechnologyElement element, UITechnologyElement topLevel, UITechnologyManager manager, string managerName)
		{
			this.element = element;
			this.topLevel = topLevel;
			this.manager = manager;
			this.managerName = managerName;
		}

		public override void CacheProperties()
		{
			throw new NotImplementedException();
		}

		public override int ChildIndex
		{
			get { return element.ChildIndex; }
		}

		public override string ClassName
		{
			get { return element.ClassName; }
		}

		public override string ControlTypeName
		{
			get { return element.ControlTypeName; }
		}

		public override void EnsureVisibleByScrolling(int pointX, int pointY, ref int outpointX, ref int outpointY)
		{
			element.EnsureVisibleByScrolling(pointX, pointY, ref outpointX, ref outpointY);
		}

		public override bool Equals(IUITechnologyElement element)
		{
			return this.element.Equals(element);
		}

		public override string FriendlyName
		{
			get { return element.FriendlyName; }
		}

		public override void GetBoundingRectangle(out int left, out int top, out int width, out int height)
		{
			element.GetBoundingRectangle(out left, out top, out width, out height);
		}

		public override void GetClickablePoint(out int pointX, out int pointY)
		{
			element.GetClickablePoint(out pointX, out pointY);
		}

		public override object GetNativeControlType(NativeControlTypeKind nativeControlTypeKind)
		{
			return element.GetNativeControlType(nativeControlTypeKind);
		}

		public override object GetPropertyValue(string propertyName)
		{
			return element.GetPropertyValue(propertyName);
		}

		public override string GetQueryIdForRelatedElement(UITestElementKind relatedElement, object additionalInfo, out int maxDepth)
		{
			return element.GetQueryIdForRelatedElement(relatedElement, additionalInfo, out maxDepth);
		}

		public override System.Windows.Forms.AccessibleStates GetRequestedState(System.Windows.Forms.AccessibleStates requestedState)
		{
			return element.GetRequestedState(requestedState);
		}

		public override bool GetRightToLeftProperty(RightToLeftKind rightToLeftKind)
		{
			return element.GetRightToLeftProperty(rightToLeftKind);
		}

		public override int GetScrolledPercentage(ScrollDirection scrollDirection, IUITechnologyElement scrollElement)
		{
			return element.GetScrolledPercentage(scrollDirection, scrollElement);
		}

		public override bool InitializeProgrammaticScroll()
		{
			return element.InitializeProgrammaticScroll();
		}

		public override void InvokeProgrammaticAction(ProgrammaticActionOption programmaticActionOption)
		{
			element.InvokeProgrammaticAction(programmaticActionOption);
		}

		public override bool IsLeafNode
		{
			get { return element.IsLeafNode; }
		}

		public override bool IsPassword
		{
			get { return element.IsPassword; }
		}

		public override bool IsTreeSwitchingRequired
		{
			get { return element.IsTreeSwitchingRequired; }
		}

		public override string Name
		{
			get { return element.Name; }
		}

		public override object NativeElement
		{
			get { return element.NativeElement; }
		}

		public override IQueryElement QueryId
		{
			get { return element.QueryId; }
		}

		public override void ScrollProgrammatically(ScrollDirection scrollDirection, ScrollAmount scrollAmount)
		{
			element.ScrollProgrammatically(scrollDirection, scrollAmount);
		}

		public override void SetFocus()
		{
			element.SetFocus();
		}

		public override IUITechnologyElement SwitchingElement
		{
			get
			{
				return element.SwitchingElement;
			}
			set
			{
				element.SwitchingElement = value;
			}
		}

		public override UITechnologyManager TechnologyManager
		{
			get { return manager; }
		}

		public override string TechnologyName
		{
			get { return managerName; }
		}

		public override UITechnologyElement TopLevelElement
		{
			get
			{
				return topLevel;
			}
			set
			{
				topLevel = value;
			}
		}

		public override string Value
		{
			get
			{
				return element.Value;
			}
			set
			{
				element.Value = value;
			}
		}

		public override void WaitForReady()
		{
			element.WaitForReady();
		}

		public override IntPtr WindowHandle
		{
			get { return element.WindowHandle; }
		}
	}
}
